<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>

  <div id="app">
    <button-counter num='10'></button-counter>
    <button-counter></button-counter>
    <button-counter></button-counter>
  </div>
  
  <script>

  //全局组件
  Vue.component('ButtonCounter', {
    //每个组件数据的独立拷贝
      data() {
        return {
          num: 10
        }
      },
      template:`
      <div>
        <h1>{{num}}</h1>
        <button @click="increment()">加{{num}}</button>
      </div>
      `,
      methods:{
        increment(){
          this.num +=1;
        }
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {}
    })

  

  </script>

</body>

</html>